home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / clients / editres / svpopup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-12  |  9.4 KB  |  330 lines

  1. /*
  2.  * $XConsortium: svpopup.c,v 1.13 91/07/09 09:46:48 rws Exp $
  3.  *
  4.  * Copyright 1989 Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of M.I.T. not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  M.I.T. makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  *
  23.  * Author:  Chris D. Peterson, MIT X Consortium
  24.  */
  25.  
  26. #ifdef MSDOS
  27. #include "X11/Intrinsc.h"      /* QDK 05/11/1994 12:54pm. */
  28. #else
  29. #include "X11/Intrinsic.h"
  30. #endif
  31. #include <X11/StringDefs.h>    /* Get standard string definations. */
  32. #include <X11/Xatom.h>
  33. #include <X11/cursorfont.h>
  34. #include <X11/Shell.h>
  35.  
  36. #include "editresP.h"
  37.  
  38. #include <X11/Xaw/AsciiText.h>
  39. #include <X11/Xaw/Cardinals.h>    
  40. #include <X11/Xaw/Command.h>    
  41. #include <X11/Xaw/Form.h>
  42. #include <X11/Xaw/Label.h>    
  43.  
  44. #include <stdio.h>
  45.  
  46. extern void SetMessage(), SetCommand(), InsertWidgetFromNode();
  47. extern void GetAllStrings(), PopupCentered();
  48.  
  49. static void _SetField(), CreateSetValuesPopup();
  50. static void DoSetValues(), CancelSetValues();
  51.  
  52. /*    Function Name: PopupSetValues
  53.  *    Description: This function pops up the setvalues dialog
  54.  *    Arguments: parent - the parent of the setvalues popup.
  55.  *                 event - the event that caused this popup, or NULL.
  56.  *    Returns: none
  57.  */
  58.  
  59. /* ARGSUSED */
  60. void
  61. PopupSetValues(parent, event)
  62. Widget parent;
  63. XEvent * event;
  64. {
  65.     Arg args[1];
  66.  
  67.     if (global_tree_info == NULL) {
  68.     SetMessage(global_screen_data.info_label,
  69.            "No widget Tree is avaliable.");
  70.     return;
  71.     }
  72.  
  73. /* 
  74.  * Check and possibly create the popup.
  75.  */
  76.  
  77.     if (global_screen_data.set_values_popup == NULL)
  78.     CreateSetValuesPopup(parent, &global_screen_data);
  79.  
  80. /*
  81.  * Clear out the old strings, and set the active widget to the name widget.
  82.  */
  83.  
  84.     XtSetArg(args[0], XtNstring, "");
  85.     XtSetValues(global_screen_data.res_text, args, ONE);
  86.     XtSetValues(global_screen_data.val_text, args, ONE);
  87.  
  88.     _SetField(global_screen_data.res_text, global_screen_data.val_text);
  89.  
  90. /*
  91.  * Pop it up.
  92.  */
  93.  
  94.     PopupCentered(event, global_screen_data.set_values_popup, XtGrabNone);
  95. }
  96.  
  97. /*    Function Name: ModifySVEntry
  98.  *    Description: Action routine that can be bound to the set values 
  99.  *                   dialog box's Text Widget that will send input to the 
  100.  *                   field specified.
  101.  *    Arguments:   (Standard Action Routine args) 
  102.  *    Returns:     none.
  103.  */
  104.  
  105. /* ARGSUSED */
  106. void 
  107. ModifySVEntry(w, event, params, num_params)
  108. Widget w;
  109. XEvent *event;
  110. String * params;
  111. Cardinal * num_params;
  112. {
  113.     Widget new, old;
  114.     char msg[BUFSIZ];
  115.     
  116.     if (*num_params != 1) {
  117.     strcpy(msg, 
  118.            "Error: SVActiveEntry Action must have exactly one argument.");
  119.     SetMessage(global_screen_data.info_label, msg);
  120.     return;
  121.     }
  122.     
  123.     switch (params[0][0]) {
  124.     case 'r':
  125.     case 'R':
  126.     new = global_screen_data.res_text;
  127.     old = global_screen_data.val_text;
  128.     break;
  129.     case 'v':
  130.     case 'V':
  131.     new = global_screen_data.val_text;
  132.     old = global_screen_data.res_text;
  133.     break;
  134.     default:
  135.     sprintf(msg, "%s %s", "Error: SVActiveEntry Action's first Argument",
  136.         "must be either 'Resource' or 'Value'.");
  137.     SetMessage(global_screen_data.info_label, msg);
  138.     return;
  139.     }
  140.     
  141.     _SetField(new, old);
  142. }
  143.  
  144. /************************************************************
  145.  *
  146.  * Private Functions
  147.  *
  148.  ************************************************************/
  149.  
  150. /*    Function Name: _SetField
  151.  *    Description: Sets the current text entry field.
  152.  *    Arguments: new, old - new and old text fields.
  153.  *    Returns: none
  154.  */
  155.  
  156. static void
  157. _SetField(new, old)
  158. Widget new, old;
  159. {
  160.     Arg args[2];
  161.     Pixel new_border, old_border, old_bg;
  162.     
  163.     if (!XtIsSensitive(new)) {
  164.     XBell(XtDisplay(old), 0); /* Don't set field to an inactive Widget. */
  165.     return;
  166.     }
  167.     
  168.     XtSetKeyboardFocus(XtParent(new), new); 
  169.     
  170.     XtSetArg(args[0], XtNborderColor, &old_border);
  171.     XtSetArg(args[1], XtNbackground, &old_bg);
  172.     XtGetValues(new, args, TWO);
  173.     
  174.     XtSetArg(args[0], XtNborderColor, &new_border);
  175.     XtGetValues(old, args, ONE);
  176.     
  177.     if (old_border != old_bg)    /* Colors are already correct, return. */
  178.     return;
  179.  
  180.     XtSetArg(args[0], XtNborderColor, old_border);
  181.     XtSetValues(old, args, ONE);
  182.  
  183.     XtSetArg(args[0], XtNborderColor, new_border);
  184.     XtSetValues(new, args, ONE);
  185. }
  186.  
  187. /*    Function Name: CreateSetValuesPopup
  188.  *    Description: Creates the setvalues popup.
  189.  *    Arguments: parent - the parent of the popup.
  190.  *                 scr_data - the data about this screen.
  191.  *    Returns: the set values popup.
  192.  */
  193.  
  194. static void
  195. CreateSetValuesPopup(parent, scr_data)
  196. Widget parent;
  197. ScreenData * scr_data;
  198. {
  199.     Widget form, cancel, do_it, label;
  200.     Widget res_label;
  201.     Arg args[10];
  202.     Cardinal num_args;
  203.     
  204.     scr_data->set_values_popup = XtCreatePopupShell("setValuesPopup", 
  205.                             transientShellWidgetClass, 
  206.                             parent, NULL, ZERO);
  207.  
  208.     form = XtCreateManagedWidget("form", formWidgetClass, 
  209.                  scr_data->set_values_popup, NULL, ZERO);
  210.  
  211.     num_args = 0;
  212.     label = XtCreateManagedWidget("label", labelWidgetClass,
  213.                   form, args, num_args);
  214.  
  215.  
  216.     num_args = 0;
  217.     XtSetArg(args[num_args], XtNfromVert, label); num_args++;
  218.     res_label = XtCreateManagedWidget("resourceLabel", labelWidgetClass,
  219.                   form, args, num_args);
  220.  
  221.     num_args = 0;
  222.     XtSetArg(args[num_args], XtNfromVert, label); num_args++;
  223.     XtSetArg(args[num_args], XtNfromHoriz, res_label); num_args++;
  224.     scr_data->res_text = XtCreateManagedWidget("resourceText", 
  225.                           asciiTextWidgetClass,
  226.                           form, args, num_args);
  227.  
  228.     num_args = 0;
  229.     XtSetArg(args[num_args], XtNfromVert, scr_data->res_text); num_args++;
  230.     (void)  XtCreateManagedWidget("valueLabel", labelWidgetClass,
  231.                   form, args, num_args);
  232.  
  233.     num_args = 0;
  234.     XtSetArg(args[num_args], XtNfromHoriz, res_label); num_args++;
  235.     XtSetArg(args[num_args], XtNfromVert, scr_data->res_text); num_args++;
  236.     scr_data->val_text = XtCreateManagedWidget("valueText", 
  237.                           asciiTextWidgetClass,
  238.                           form, args, num_args);
  239.   
  240.     num_args = 0;
  241.     XtSetArg(args[num_args], XtNfromVert, scr_data->val_text); num_args++;
  242.     do_it = XtCreateManagedWidget("setValues", commandWidgetClass, 
  243.                       form, args, num_args);
  244.  
  245.     num_args = 0;
  246.     XtSetArg(args[num_args], XtNfromVert, scr_data->val_text); num_args++;
  247.     XtSetArg(args[num_args], XtNfromHoriz, do_it); num_args++;
  248.     cancel = XtCreateManagedWidget("cancel", commandWidgetClass,
  249.                    form, args, num_args);
  250.  
  251.     XtAddCallback(do_it, XtNcallback, DoSetValues, NULL);
  252.     XtAddCallback(cancel, XtNcallback, CancelSetValues, NULL);
  253.  
  254. /*
  255.  * Initialize the text entry fields.
  256.  */
  257.  
  258.     {
  259.     Pixel color;
  260.  
  261.     num_args = 0;
  262.     XtSetArg(args[num_args], XtNbackground, &color); num_args++;
  263.     XtGetValues(scr_data->val_text, args, num_args);
  264.  
  265.     num_args = 0;
  266.     XtSetArg(args[num_args], XtNborderColor, color); num_args++;
  267.     XtSetValues(scr_data->val_text, args, num_args);
  268.  
  269.     XtSetKeyboardFocus(form, scr_data->res_text);
  270.     }
  271. }
  272.  
  273. /*    Function Name: DoSetValues
  274.  *    Description: Performs a SetValues.
  275.  *    Arguments: w - the widget that called this.
  276.  *                 junk, garbage - ** UNUSED **.
  277.  *    Returns: none.
  278.  */
  279.  
  280. /* ARGSUSED */
  281. static void
  282. DoSetValues(w, junk, garbage)
  283. Widget w;
  284. caddr_t junk, garbage;
  285. {
  286.     ProtocolStream * stream = &(global_client.stream);
  287.     char *res_name, *res_value;
  288.     Arg args[1];
  289.     Cardinal i;
  290.  
  291.     if (global_tree_info->num_nodes == 0) {
  292.     SetMessage(global_screen_data.info_label,
  293.            "There are no currently active widgets.");
  294.     return;
  295.     }
  296.         
  297.     XtSetArg(args[0], XtNstring, &res_name);
  298.     XtGetValues(global_screen_data.res_text, args, ONE);
  299.  
  300.     XtSetArg(args[0], XtNstring, &res_value);
  301.     XtGetValues(global_screen_data.val_text, args, ONE);
  302.     
  303.     _XEditResResetStream(stream);
  304.     _XEditResPutString8(stream, res_name);
  305.     _XEditResPutString8(stream, XtRString);
  306.     _XEditResPutString8(stream, res_value);
  307.     _XEditResPut16(stream, global_tree_info->num_nodes);
  308.  
  309.     for (i = 0; i < global_tree_info->num_nodes; i++) 
  310.     InsertWidgetFromNode(stream, global_tree_info->active_nodes[i]);
  311.  
  312.     SetCommand(w, LocalSetValues, NULL);
  313. }
  314.  
  315. /*    Function Name: CancelSetValues
  316.  *    Description: Pops down the setvalues popup.
  317.  *    Arguments: w - any grandchild of the popup.
  318.  *                 junk, garbage - ** UNUSED **.
  319.  *    Returns: none.
  320.  */
  321.  
  322. /* ARGSUSED */
  323. static void
  324. CancelSetValues(w, junk, garbage)
  325. Widget w;
  326. caddr_t junk, garbage;
  327. {
  328.     XtPopdown(XtParent(XtParent(w))); 
  329. }
  330.